<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>主页示例</title>
    <h1>房屋环境实时监测系统</h1>

    <style>
        /* 全局样式重置，确保不同浏览器的默认样式一致性 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        /* 整体页面布局与背景设置 */
        body {
            font-family: Arial, sans-serif;
            background-color: #f0f0f0;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            background-image: url('t0163975e6092dd2eda.jpg');
            background-size: cover;
            background-position: center;
            background-repeat: no-repeat;
            background: linear-gradient(to bottom, rgba(240, 240, 240, 0.9), rgba(240, 240, 240, 1));
        }

        body::before {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-image: url('beijing.jpg');
            background-size: cover;
            background-position: center;
            background-repeat: no-repeat;
            filter: blur(5px);
            z-index: -1;
        }

        /* 页面头部导航栏样式 */
        nav {
            width: 100%;
            background-color: #380794;
            box-shadow: 0 2px 5px rgba(203, 72, 72, 0.3);
            padding: 10px 0;
            text-align: center;
            display: flex;
            justify-content: center;
            border-bottom: 2px solid #555;
        }

        nav a {
            text-decoration: none;
            color: #ccc;
            font-weight: bold;
            margin: 0 20px;
            transition: color 0.3s ease;
            display: flex;
            align-items: center;
            background: linear-gradient(to bottom, #333, #333);
            padding: 5px 10px;
            border-radius: 3px;
        }

        nav a img {
            margin-right: 5px;
        }

        nav a:hover {
            color: #fff;
            transform: translateY(-3px);
            box-shadow: 0 2px 3px rgba(0, 0, 0, 0.2);
            background: linear-gradient(to bottom, #555, #111);
            transition: all 0.3s ease;
        }

        /* 对输入框和按钮所在的区域（表单及相关容器）设置样式 */
      .main-content {
            background-color: #fff;
            border: 1px solid #ccc;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
            padding: 40px;
            width: 80%;
            max-width: 800px;
            margin-top: 30px;
            display: flex;
            flex-direction: column;
            align-items: center;
        }

      .main-content:hover {
            transform: scale(1.02);
            box-shadow: 0 0 15px rgba(0, 0, 0, 0.3);
        }

        /* 标题样式，使其更加突出 */
        h1 {
            color: #333;
            text-align: center;
            font-size: 36px;
            margin-bottom: 20px;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
        }

        /* 每个输入框和对应的标签设置样式 */
        label {
            display: block;
            margin-bottom: 8px;
            color: #333;
            font-weight: bold;
            font-size: 18px;
        }

        input[type="text"],
        textarea {
            width: 100%;
            padding: 15px;
            border: 1px solid #ccc;
            border-radius: 5px;
            transition: border-color 0.3s ease;
            margin-bottom: 20px;
            background-color: #f9f9f9;
            font-size: 16px;
            position: relative;
        }

        input[type="text"]::before,
        textarea::before {
            content: "";
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 1px;
            background-color: #ccc;
            opacity: 0.5;
        }

        input[type="text"]:focus,
        textarea:focus {
            border-color: #007BFF;
            box-shadow: 0 0 5px #007BFF;
            color: #333;
            border-bottom-color: #007BFF;
        }

        input[type="text"]:focus::before,
        textarea:focus::before {
            height: 2px;
            background-color: #007BFF;
            opacity: 1;
        }

        input[type="text"]::-webkit-input-placeholder,
        textarea::-webkit-input-placeholder {
            color: #ccc;
        }

        input[type="text"]::-moz-placeholder,
        textarea::-moz-placeholder {
            color: #ccc;
        }

        input[type="text"]:-ms-input-placeholder,
        textarea:-ms-input-placeholder {
            color: #ccc;
        }

        input[type="text"]::placeholder,
        textarea::placeholder {
            color: #ccc;
        }

        /* 按钮样式设置 */
        input[type="button"] {
            background-color: #333;
            color: #fff;
            padding: 15px 30px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s ease;
            font-size: 16px;
            margin-top: 20px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
            background-image: linear-gradient(to bottom, #333, #111);
            position: relative;
        }

        input[type="button"]::after {
            content: "";
            position: absolute;
            top: 50%;
            left: 50%;
            width: 20px;
            height: 20px;
            border: 2px solid #fff;
            border-top-color: transparent;
            border-radius: 50%;
            transform: translate(-50%, -50%);
            opacity: 0;
            animation: loading 1s linear infinite;
        }

        input[type="button"]:active::after {
            opacity: 1;
        }

        @keyframes loading {
            from {
                transform: translate(-50%, -50%) rotate(0deg);
            }
            to {
                transform: translate(-50%, -50%) rotate(360deg);
            }
        }

        /* 给温度输入框添加特殊样式 */
        #temp {
            background-color: #ffe6e6;
            color: #FF5733;
            border: 2px solid #FF5733;
            border-radius: 8px;
            box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.1);
            position: relative;
        }

        #temp[data-value] {
            box-shadow: 0 0 3px rgba(0, 0, 0, 0.1);
        }

        #temp:hover::after {
            content: "当前环境温度";
            position: absolute;
            bottom: -30px;
            left: 50%;
            transform: translateX(-50%);
            background-color: #333;
            color: #fff;
            padding: 5px 10px;
            border-radius: 3px;
            opacity: 0;
            transition: opacity 0.3s ease;
        }

        #temp:hover {
            cursor: pointer;
        }

        #temp:hover::after {
            opacity: 1;
        }

        /* 给湿度输入框添加特殊样式 */
        #hum {
            background-color: #e6ffe6;
            color: #33FF57;
            border: 2px solid #33FF57;
            border-radius: 8px;
            box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.1);
            position: relative;
        }

        #hum[data-value] {
            box-shadow: 0 0 3px rgba(0, 0, 0, 0.1);
        }

        #hum:hover::after {
            content: "当前环境湿度";
            position: absolute;
            bottom: -30px;
            left: 50%;
            transform: translateX(-50%);
            background-color: #333;
            color: #fff;
            padding: 5px 10px;
            border-radius: 3px;
            opacity: 0;
            transition: opacity 0.3s ease;
        }

        #hum:hover {
            cursor: pointer;
        }

        #hum:hover::after {
            opacity: 1;
        }

        /* 给CO2输入框添加特殊样式 */
        #CO2 {
            background-color: #e6e6ff;
            color: #5733FF;
            border: 2px solid #5733FF;
            border-radius: 8px;
            box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.1);
            position: relative;
        }

        #CO2[data-value] {
            box-shadow: 0 0 3px rgba(0, 0, 0, 0.1);
        }

        #CO2:hover::after {
            content: "当前环境CO2浓度";
            position: absolute;
            bottom: -30px;
            left: 50%;
            transform: translateX(-50%);
            background-color: #333;
            color: #fff;
            padding: 5px 10px;
            border-radius: 3px;
            opacity: 0;
            transition: opacity 0.3s ease;
        }

        #CO2:hover {
            cursor: pointer;
        }

        #CO2:hover::after {
            opacity: 1;
        }

        /* 历史记录文本区域样式 */
        #d4 {
            background-color: #f9f9f9;
            color: #666;
            font-size: 16px;
            padding: 15px;
            border: 1px solid #ccc;
            border-radius: 5px;
            width: 100%;
            max-height: 200px;
            overflow-y: auto;
            box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
            background-image: linear-gradient(to bottom right, #f9f9f9, #ffffff);
            -webkit-scrollbar {
                width: 6px;
            }

            -webkit-scrollbar-track {
                background: #f9f9f9;
            }

            -webkit-scrollbar-thumb {
                background: #ccc;
                border-radius: 3px;
                transition: background-color 0.3s ease;
            }

            -webkit-scrollbar-thumb:hover {
                background: #999;
            }
        }

        .footer-saying {
            background-color: #e6e6e6;
            text-align: center;
            padding: 30px;
            border-top: 2px solid #ccc;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            position: relative;
        }

        /* 谚语文字样式 */
      .footer-saying p {
            font-size: 20px;
            color: #333;
            margin: 0;
            font-family: 'Arial', sans-serif;
            line-height: 1.5;
            font-weight: bold; /* 字体加粗 */
            font-style: italic; /* 字体倾斜 */
            background-color: #f0f0f0; /* 文字背景颜色 */
            padding: 10px; /* 文字背景内边距 */
            border-radius: 5px; /* 文字背景边框圆角 */
        }

        /* 在谚语下方添加一条装饰线 */
      .footer-saying::after {
            content: "";
            display: block;
            width: 50%;
            height: 1px;
            background-color: #999;
            margin: 20px auto;
        }

        /* 给谚语添加一个鼠标悬停效果，改变颜色 */
      .footer-saying p:hover {
            color: #007bff;
        }



    </style>


    <script>
        function time() {
            // console.log("test");
            // var v1 = document.getElementById("d1").value;
            // var v2 = document.getElementById("d2").value;
            var req = "time";
            // console.log(req);

            var xhr = new XMLHttpRequest();
            var url = "";
            xhr.open("post", url, true);
            xhr.send(req);
            xhr.onload = function () {
                var response = xhr.responseText;
                console.log(response);
                document.getElementById("d4").value = response;
                // var response = xhr.responseText;
                // console.log(response);
                // document.getElementById("d2").value = response;
            }
        }
    </script>

    <script type="text/javascript">
        function init() {
            refresh();
        }

        function refresh() {
            var xhr = new XMLHttpRequest();
            // 创建XMLHttpRequest对象
            var url = "";
            // 请求的URL

            xhr.open("POST", url, true);
            // 配置请求：POST方法、URL、异步请求

            var post_req = {
                "type": 1,
                "limit": "all"
            };
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    // 请求完成且成功
                    var response = xhr.responseText;
                    // 获取响应数据
                    var info = JSON.parse(response);
                    // 将json字符串反序列化为json对象
                    console.log(info);
                    // 在浏览器控制台打印响应数据
                    for (var i = 0; i < info.data.length; i++) {
                        // console.log('data = ', info.data[i].val)

                        if (info.data[i].key == 303) {
                            document.getElementById('temp').value = info.data[i].val;
                        } else if (info.data[i].key == 304) {
                            document.getElementById('hum').value = info.data[i].val;
                        } else if (info.data[i].key == 104) {
                            document.getElementById('CO2').value = info.data[i].val;
                        }


                    }
                }
            };

            // 将json对象序列化为json字符串
            xhr.send(JSON.stringify(post_req));
            // 发送请求，并将数据转换为JSON字符串
        }
    </script>
</head>

<body onload="init()">
    <nav>
        <a href="index.html">
            <img src="icons/home-icon.svg" alt="※" width="20" height="20">
            主页
        </a>
        <a href="stm32.html">stm32示例页面</a>
        <a href="modbus.html">modbus示例页面</a>
        <a href="shipin.html">视频监控页面</a>
    </nav> 

    <div>
        <form>
            <br />


            <label for="temp">温度</label>
            <input type="text" id="temp" value="" />
            <label for="hum">湿度</label>
            <input type="text" id="hum" value="" />
            <label for="ill">CO2</label>
            <input type="text" id="CO2" value="" />
            <br>

            <div class="footer-saying">
                <p>千磨万击还坚劲，任尔东西南北风</p>
            </div>
            <p style="text-align: center; margin-top: 500px;">千磨万击还坚劲，任尔东西南北风</p>
            <!-- <textarea name="his" rows="8" cols="50" value="history" id="d4"></textarea>
            <br>
            <input type="button" name="bin" onclick="time()" value="查询历史记录">
            <br> -->


            <br>
        </form>
    </div>
</body>

</html>